package com.offcn;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class ProducerSendP2Pdemo001 {

    public static void main(String[] args) throws JMSException {
        //1、创建连接工厂
        ConnectionFactory connectionFactory=new ActiveMQConnectionFactory("tcp://192.168.188.133:61616");

        //2、从连接工厂获取一个连接
        Connection connection = connectionFactory.createConnection();
        //开启连接
        connection.start();

        //3、创建一个会话 参数1：是否开启事务
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        //4、通过会话创建接收消息队列
        Queue queue = session.createQueue("testqueue1");

        //5、创建生产者对象
        MessageProducer producer = session.createProducer(queue);

        //6、创建普通文本消息
        TextMessage message = session.createTextMessage("Hello jms4-接收方开启事务");

        //7、调用生产者对象发送消息
        producer.send(message);
        System.out.println("消息发送成功");
        //8、关闭相关资源
        producer.close();
        session.close();
        connection.close();

    }
}
